package com.oocl.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.oocl.dao.FoodAdDao;
import com.oocl.dao.base.BaseJPADaoUtil;
import com.oocl.entity.FoodAd;
import com.oocl.entity.OrderComment;


@Repository("foodAdDao")
public class FoodAdDaoImpl extends BaseJPADaoUtil implements FoodAdDao{

	
	/*
     * @Method  findFoodAdsByMerchant
     * @function load FoodAds by   Icnum
     * @param  icnum Merchant Icnum 
     * @return list FoodAd List
     * @author lionel
     * @date 2017-8-13
     * */
	public List<FoodAd> findFoodAdsByMerchant(String icnum) {
		String sql = "select fad from FoodAd fad left join fetch fad.merchant m where m.icnum=:icnum ";
		List<FoodAd> list =  entityManager.createQuery(sql)
		                       .setParameter("icnum", icnum)
		                       .getResultList();
		return list;
	}

	@Override
	public FoodAd getFoodsAdByFoodNameIcn(String foodName, String icnum) {
		String sql = "select fad from FoodAd fad left join fetch fad.merchant m left join fetch fad.food f where f.fname=:fname and m.icnum=:icnum";
		List<FoodAd> list = entityManager.createQuery(sql)
                      .setParameter("fname", foodName)
                       .setParameter("icnum", icnum)
                     .getResultList();
		if(list.size()>0){
			return list.get(0);
		}
		return new FoodAd();
	}

}
